//
//  VisitorLoginView.swift
//  SinaWeiBo
//
//  Created by 有风 on 16/2/16.
//  Copyright © 2016年 YouFeng. All rights reserved.
//

import UIKit
import SnapKit

class VisitorLoginView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //设置页面信息
    func setupInfoWith(tipText: String,imageName: String?) {
        tipLabel.text = tipText
        if imageName != nil {
            circleIcon.image = UIImage(named: imageName!)
            
            backgroundImage.hidden = true
            largeHouse.hidden = true
            
        }else{
            makeRotation()
        }
        
    }
    //旋转
    private func makeRotation() {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        //重复次数
        anim.repeatCount = MAXFLOAT
        anim.toValue = 2 * M_PI
        
        //设置动画时间
        anim.duration = 15
        anim.removedOnCompletion = false
        circleIcon.layer.addAnimation(anim, forKey: nil)
    }

    private func setupUI() {
        addSubview(circleIcon)
        addSubview(backgroundImage)
        addSubview(largeHouse)
        addSubview(tipLabel)
        addSubview(loginButton)
        addSubview(registButton)
        
        
        //SnapKit布局
        circleIcon.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
        }
        largeHouse.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circleIcon.snp_center)
        }
        tipLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(circleIcon.snp_bottom).offset(16)
            make.centerX.equalTo(circleIcon.snp_centerX)
            //宽度
            make.width.equalTo(230)
            //高度
            make.height.equalTo(40)
        }
        loginButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(tipLabel.snp_left)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        registButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(tipLabel.snp_right)
            make.top.equalTo(tipLabel.snp_bottom).offset(16)
            make.width.equalTo(100)
        }
        backgroundImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circleIcon.snp_center)
        }
        
        let value: CGFloat = 236.0/255.0
        self.backgroundColor = UIColor(red: value, green: value, blue: value, alpha: 1.0)
        loginButton.addTarget(self, action: "loginButtonClick", forControlEvents: .TouchUpInside)
        registButton.addTarget(self, action: "registButtonClick", forControlEvents: .TouchUpInside)
        
    }
    
    @objc private func loginButtonClick() {
        print(__FUNCTION__)
                
    }
    
    @objc private func registButtonClick() {
        print(__FUNCTION__)
    }
    //子视图空间 懒加载
    private lazy var backgroundImage: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    
    private lazy var circleIcon: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    private lazy var largeHouse: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var tipLabel: UILabel = UILabel(text: "关注一些人,回这里看看有什么惊喜", fontSize: 14, textColor: UIColor.lightGrayColor())
    
    
    //登录按钮
    private lazy var loginButton: UIButton = UIButton(backImageName: "common_button_white_disable",title: "登录",textColor: UIColor.lightGrayColor())
    
    
    //注册按钮
    private lazy var registButton: UIButton = UIButton(backImageName: "common_button_white_disable", title: "注册", textColor: UIColor.orangeColor())
    
    
}
